﻿using System;
using System.Web;
using System.Web.Optimization;

namespace webApi
{
    internal static class BundleExtensions
    {
        public static System.Web.Optimization.Bundle WithLastModifiedToken(this System.Web.Optimization.Bundle bundle)
        {
            return bundle;
        }
        public class LastModifiedBundleTransform : System.Web.Optimization.IBundleTransform
        {
            public void Process(System.Web.Optimization.BundleContext context, System.Web.Optimization.BundleResponse response)
            {
                foreach (var file in response.Files)
                {
                    if (file.IncludedVirtualPath.IndexOf(".min.", StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        file.IncludedVirtualPath = string.Concat(file.IncludedVirtualPath, "?v=", DateTime.Now.ToString());
                    }
                }
            }
        }
    }
    public class BundleConfig
    {
        // 有关捆绑的详细信息，请访问 https://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            // 使用要用于开发和学习的 Modernizr 的开发版本。然后，当你做好
            // 生产准备就绪，请使用 https://modernizr.com 上的生成工具仅选择所需的测试。
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));

            bundles.Add(new System.Web.Optimization.ScriptBundle("~/Content/index/plugin").Include(
                "~/Content/index/polyfill.min.js"
                , "~/Content/index/qrcode.js"
                , "~/Content/index/FileSaver/Blob.js"
                , "~/Content/index/FileSaver/canvas-toBlob.js"
                , "~/Content/index/FileSaver/FileSaver.js"
                , "~/Content/index/FileSaver/jszip.min.js"
                , "~/Content/index/crypto-js.js")
                .WithLastModifiedToken());
            bundles.Add(new System.Web.Optimization.ScriptBundle("~/Content/index/mobile").Include(
               "~/Content/index/index.js"
               , "~/Content/index/index.vant.js")
               .WithLastModifiedToken());
            YYS.Controllers.pcController.RegisterBundles(bundles);
            YYS.Controllers.wxController.RegisterBundles(bundles);
            System.Web.Optimization.BundleTable.EnableOptimizations = true;
        }
    }
}
